package com.empire.module.sporttery.service.football500yazim;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500yazim.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500yazim.Football500YazImDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500yazim.Football500YazImMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 亚盘实时 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500YazImServiceImpl implements Football500YazImService {

    @Resource
    private Football500YazImMapper football500YazImMapper;

    @Override
    public Integer createFootball500YazIm(Football500YazImSaveReqVO createReqVO) {
        // 插入
        Football500YazImDO football500YazIm = BeanUtils.toBean(createReqVO, Football500YazImDO.class);
        football500YazImMapper.insert(football500YazIm);
        // 返回
        return football500YazIm.getId();
    }

    @Override
    public void updateFootball500YazIm(Football500YazImSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500YazImExists(updateReqVO.getId());
        // 更新
        Football500YazImDO updateObj = BeanUtils.toBean(updateReqVO, Football500YazImDO.class);
        football500YazImMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500YazIm(Integer id) {
        // 校验存在
        validateFootball500YazImExists(id);
        // 删除
        football500YazImMapper.deleteById(id);
    }

    private void validateFootball500YazImExists(Integer id) {
        if (football500YazImMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_YAZ_IM_NOT_EXISTS);
        }
    }

    @Override
    public Football500YazImDO getFootball500YazIm(Integer id) {
        return football500YazImMapper.selectById(id);
    }

    @Override
    public PageResult<Football500YazImDO> getFootball500YazImPage(Football500YazImPageReqVO pageReqVO) {
        return football500YazImMapper.selectPage(pageReqVO);
    }

}